/*--
 * Pair.cs: Implements a small utility class for storing pairs of variables.
 *--
 * For more information, please visit the Metashell Project site:
 *   http://code.google.com/p/metashell/
 *--
 * (c) 2006 Christopher E. Granade.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; exactly version 2
 * of the License applies to this software.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

using System;

namespace Metashell.Core.Utility {
	
	/// <summary>
	/// Utility class that represents a pair of related values. Inherits
	/// <see cref="System.IComparable" />, and performs a lexographical comparison.
	/// </summary>
	/// <param name="first_t">Type of the first value stored in the Pair.
	/// 	Must implement <see cref="System.IComparable" />.</param>
	/// <param name="second_t">Type of the second values stored in the Pair.
	/// 	Must implement <see cref="System.IComparable" />.</param>
	public struct Pair<first_t, second_t> : IComparable<Pair<first_t, second_t>> 
		where first_t : IComparable<first_t>
		where second_t : IComparable<second_t>
	{
		
		// Implments a lexographical comparison.
		public int CompareTo(Pair<first_t, second_t> b) {
			
			int one = this.First.CompareTo(b.First),
			    two = this.Second.CompareTo(b.Second);			
		
			// Are the first equal?
			if (one == 0) {
				// OK, then. Just pass off the second.
				return two;
			} else {
				// There's no tie, so return the first.
				return one;
			}
		}
	
		public first_t First;
		public second_t Second;		
		
	}
	
}
